package com.lapelittle.framework.mapper;

import com.lapelittle.framework.entity.SysUserToken;
import org.apache.ibatis.annotations.*;

@Mapper
public interface SysUserTokenMapper {
    @Select("SELECT * FROM sys_user_token WHERE token = #{token}")
    SysUserToken findByToken(String token);
    
    @Select("SELECT * FROM sys_user_token WHERE user_id = #{userId}")
    SysUserToken findByUserId(Long userId);
    
    @Insert("INSERT INTO sys_user_token(user_id, token, expire_time) VALUES(#{userId}, #{token}, #{expireTime})")
    int insert(SysUserToken token);
    
    @Update("UPDATE sys_user_token SET token = #{token}, expire_time = #{expireTime} WHERE user_id = #{userId}")
    int update(SysUserToken token);
    
    @Delete("DELETE FROM sys_user_token WHERE user_id = #{userId}")
    int deleteByUserId(Long userId);

    @Delete("DELETE FROM sys_user_token WHERE expire_time < NOW()")
int deleteExpiredTokens(); 
} 